In JavaScript, arguments
is a built-in array-like object automatically available within the scope of all non-arrow functions. It
allows you to access the arguments the function was called with, even if the number of arguments passed during the function call does not match the
number declared in the function signature. arguments
has entries for each argument, with the first entry’s index at 0
.
The arguments object has two deprecated properties called arguments.caller
and arguments.callee
, which were used to refer
to functions involved in the function invocation chain:
- The
arguments.callee
property contains the currently executing function that the arguments belong to.
- The
arguments.caller
property returns the function that invoked the currently executing function. It was replaced by
Function.prototype.caller
, which provides the same functionality.
Both arguments.caller
and arguments.callee
are non-standard, deprecated, and leak stack information, which poses security
risks and severely limits the possibility of optimizations.
Accessing arguments.callee
, Function.prototype.caller
and Function.prototype.arguments
in strict mode will
throw a TypeError
.
function whoCalled() {
if (arguments.caller == null) //Noncompliant
console.log('I was called from the global scope.');
else
console.log(arguments.caller + ' called me!'); // Noncompliant
console.log(whoCalled.caller); // Noncompliant
console.log(whoCalled.arguments); // Noncompliant
}